import 'package:flutter/material.dart';

import '../constants.dart' show AppColors;

// 定义会话数据类型
class Conversation {
  /**构造器 */
  const Conversation(
      {@required this.avatar,
      @required this.title,
      // 标题默认颜色
      this.titleColor: AppColors.TitleTextColor,
      this.des,
      @required this.updateAt,
      this.isMute: false,
      this.unreadMsgCount: 0,
      this.displayDot: false})
      : assert(avatar != null), //类型断言，可检查代码正确性
        assert(title != null),
        assert(updateAt != null);

  /**图标地址 */
  final String avatar;
  /**标题 */
  final String title;
  /**会话最新消息、简介 */
  final String des;
  /**最新消息的时间 */
  final String updateAt;
  /**是否开启静音模式/打扰 */
  final bool isMute;
  /**默认的标题颜色 */
  final int titleColor;
  /**未读消息的数量 */
  final int unreadMsgCount;
  /**是否以小圆点形式显示 */
  final bool displayDot;

  bool isAvatarFromNet() {
    if (this.avatar.indexOf('http') == 0 || this.avatar.indexOf('https') == 0) {
      return true;
    } else {
      return false;
    }
  }
}

/**所有的会话列表数据 */

class ConversationPageData {
  const ConversationPageData({this.device, this.conversations});

  final Device device;
  final List<Conversation> conversations;

  static mock() {
    return ConversationPageData(device: null, conversations: mockConversations);
  }

  static List<Conversation> mockConversations = [
    const Conversation(
      avatar:
          'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3839008355,2584870485&fm=26&gp=0.jpg',
      title: '汤姆丁111',
      des: '晚上出来玩啊！',
      updateAt: '19:56',
      isMute: false,
      unreadMsgCount: 12,
    ),
    const Conversation(
      avatar: './assets/images/default_nor_avatar.png',
      title: '群聊',
      des: '晚上出来玩啊！',
      updateAt: '19:56',
      isMute: false,
      unreadMsgCount: 29,
      displayDot: true,
    ),
    const Conversation(
      avatar:
          'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1152765155,86181646&fm=26&gp=0.jpg',
      title: '翼信客服',
      des: '晚上出来玩啊！',
      updateAt: '22:59',
      isMute: true,
      unreadMsgCount: 3,
    ),
    const Conversation(
      avatar: './assets/images/default_nor_avatar.png',
      title: '翼信公众号',
      des: '晚上出来玩啊！',
      updateAt: '18:01',
      isMute: false,
      unreadMsgCount: 0,
    ),
    const Conversation(
      avatar: './assets/images/default_nor_avatar.png',
      title: '投票易',
      des: '一起投票把',
      updateAt: ' 昨天 ',
      isMute: false,
      unreadMsgCount: 0,
    ),
    const Conversation(
      avatar: './assets/images/default_nor_avatar.png',
      title: '智慧屏',
      des: '晚上出来玩啊！',
      updateAt: '12:39',
      isMute: false,
      unreadMsgCount: 0,
    ),
    const Conversation(
      avatar:
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604477899145&di=9106a4c2b8c5afeba8590c7366178cbb&imgtype=0&src=http%3A%2F%2Fpic2.zhimg.com%2F50%2Fv2-76f2981822f9984d848f542d243a1863_hd.jpg',
      title: '李华',
      des: '晚上出来玩啊！',
      updateAt: '10:37',
      isMute: true,
      unreadMsgCount: 5,
    ),
    const Conversation(
      avatar:
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604477975584&di=c6762c39012da693deeba3bbb5db8ee6&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20181023%2F15711522f11148e487a83b16cb33a45a.jpeg',
      title: '小王',
      des: '晚上出来玩啊！',
      updateAt: ' 昨天 ',
      isMute: true,
      unreadMsgCount: 5,
    ),
    const Conversation(
      avatar:
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604477961061&di=ab903b9f086f732e0e0537a9b6f98484&imgtype=0&src=http%3A%2F%2Fpic4.zhimg.com%2F50%2Fv2-1d7f2e72132422cea9391134114e0f7b_hd.jpg',
      title: '小红',
      des: '晚上出来玩啊！',
      updateAt: '10:37',
      isMute: false,
      unreadMsgCount: 5,
    ),
    const Conversation(
      avatar:
          'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2291332875,175289127&fm=26&gp=0.jpg',
      title: '小可爱',
      des: '晚上出来玩啊！',
      updateAt: '10:37',
      isMute: false,
      unreadMsgCount: 5,
    )
  ];
}

class Device {}
